/**
 * useState使用案例
 */
import React, { useCallback, useState } from 'react';
import styled from 'styled-components';

function Difftest(props) {
  const [list, addlist] = useState([{ id: 0, text: 0 }, { id: 1, text: 1 }]);

  const setCount = useCallback(() => {
    addlist([{ id: list.length, text: list.length }, ...list]);
  }, [list]);

  return (
    <div>
      <button className="change-btn" onClick={() => setCount()}>
        添加
      </button>
      {list.map(({ text }, index) => (
        <div key={index}>{text}</div>
      ))}
    </div>
  );
}

export default Difftest;
